﻿using ConfExpert.Forms.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevTeam;

namespace ConfExpert.Forms.Sistem
{
    public partial class UsersPhoto : XForm
    {
        public UsersPhoto()
        {
            InitializeComponent();
        }

        private void UsersPhoto_Load(object sender, EventArgs e)
        {
            gridView1.Init("GetUsersPhoto");
            gridView1.BestFitColumns();
            gridView1.MakeColumnInvisible("UsersPhotoId", "DosyaGUID", "Photo2");
            gridView1.AddSummary();

            gridView1.Columns["Photo1"].Width = 360;
            gridView1.Columns["UserId"].Width = 140;
            gridView1.Columns["UserId"].OptionsColumn.AllowEdit = true;

            btnKaydet.ItemClick += btnKaydet_ItemClick;
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.EndEditing();
            DataTable dt = new DataTable();
            dt.Columns.Add("UsersPhotoId", typeof(int));
            dt.Columns.Add("UserId", typeof(int));
            
            foreach(DataRow r in gridView1.DataTable().Rows)
            {
                DataRow y = dt.NewRow();
                y["UsersPhotoId"] = r["UsersPhotoId"];
                y["UserId"] = r["UserId"];
                dt.Rows.Add(y);
            }

            string xml = dt.Serialize();
            ExecuteNonQuery("UpdUsersPhoto", xml);
        }
    }
}
